package edu.kit.csl.pisa.training;

/*
This file is part of the PISA Alignment Tool.

Copyright (C) 2013
Karlsruhe Institute of Technology
Cognitive Systems Lab (CSL)
Felix Stahlberg

PISA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PISA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PISA. If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.LinkedList;
import java.util.List;

import edu.kit.csl.pisa.datatypes.Alignment;
import edu.kit.csl.pisa.datatypes.SentenceAlignment;
import edu.kit.csl.pisa.datatypes.SentencePair;
import edu.kit.csl.pisa.models.AlignmentModel;

/**
 * This class is the trivial implementation of {@link MaximizationStrategy}.
 * Instead of maximizing P(a,f|e), it just passes through the alignments.
 */
public class IdentityMaximizationStrategy extends MaximizationStrategy {

	/**
	 * Sole constructor. Just calls the superclass constructor.
	 * {@inheritDoc}
	 */
	public IdentityMaximizationStrategy(AlignmentModel model) {
		super(model);
	}

	/**
	 * Null object (GoF) implementation. Does nothing - a stays unchanged.
	 * 
	 * @param pair the alignment to maximize
	 */
	@Override
	public void maximize(SentencePair pair)
			throws UnsupportedOperationException {
		List<Alignment> alignments = new LinkedList<Alignment>(
				pair.getAlignments());
		SentenceAlignment sa = new SentenceAlignment(null,
				pair.getSourceSentence(), pair.getTargetSentence(), 0f);
		pair.removeAllAlignments();
		for (Alignment a : alignments) {
			sa.setAlignment(a);
			pair.addAlignment(a, model.calculateAlignmentProbability(sa));
		}
	}
}
